package com.hh.TreeQuestions;


/**
 * @Author hanghao
 * @Date 2023/7/18 17:04
 * @Version 1.0
 * 二叉搜索树的最小绝对差
 * easy
 */

public class No530 {
    int min = Integer.MAX_VALUE;
    TreeNode pre;

    public int getMinimumDifference(TreeNode root) {
        if(root == null) return 0;
        traversal(root);
        return min;
    }

    private void traversal(TreeNode root) {
        if (root == null) return;
        traversal(root.left);
        if (pre != null) {
            min = Math.min(min, root.val - pre.val);
        }
        pre = root;
        traversal(root.right);
    }
}
